package objects
{
	import core.Assets;
	
	import starling.display.BlendMode;
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.events.Event;
	
	public class Background extends Sprite
	{
		private var _image1:Image;
		private var _image2:Image;
		private var _scrollSpeed:uint;
		
		public function Background()
		{
			super();
			
			this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage():void
		{
			_image1 = new Image(Assets.skyTexture);
			_image1.blendMode = BlendMode.NONE;
			this.addChild(_image1);
			
			_image2 = new Image(Assets.skyTexture);
			this.addChild(_image2);
			_image2.blendMode = BlendMode.NONE;
			_image2.y = -_image1.height;
			
			_scrollSpeed = 50;
		}
		
		public function update(deltaSmall:Number):void
		{
			// TODO: try scrolling 1 image
			// Math.ceil() used for positioning to prevent a small gap appearing between both backgrounds
			_image1.y += Math.ceil(_scrollSpeed * deltaSmall);
			
			if (_image1.y >= stage.stageHeight)
			{
				_image1.y = -stage.stageHeight;
			}
			
			_image2.y += Math.ceil(_scrollSpeed * deltaSmall);
			
			if (_image2.y >= stage.stageHeight)
			{
				_image2.y = -stage.stageHeight;
			}
		}
	}
}



































